home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameSwing.as < prev    next >
Text File  |  2006-11-29  |  4KB  |  116 lines

  1. class GameSwing extends SSObject
  2. {
  3.    var classID = SSGlobal.CLSID_SWING;
  4.    var length = 300;
  5.    var totalTime = 4;
  6.    var timeOffset = 0;
  7.    var maxAngle = 60;
  8.    var maxRad = 0;
  9.    var ax = 0;
  10.    var ay = 0;
  11.    var vx = 0;
  12.    var vy = 0;
  13.    var ltr = false;
  14.    var ang = 0;
  15.    var editor_isItem = true;
  16.    var editor_name = "Swing";
  17.    var editor_args_names = ["totalTime","timeOffset","length","maxAngle"];
  18.    var editor_args_values = [GameSwing.prototype.totalTime,GameSwing.prototype.timeOffset,GameSwing.prototype.length,GameSwing.prototype.maxAngle];
  19.    var editor_args_types = ["number","number","number","number"];
  20.    var editor_args_options = [[1,30,1],[0,10,0.1],[100,800,50],[10,90,5]];
  21.    var editor_args_descriptions = ["","","",""];
  22.    var editor_args_mode = [0,0,0];
  23.    var editor_args_component = ["NumericStepper","NumericStepper","NumericStepper","NumericStepper"];
  24.    var editor_canChangeFrame = false;
  25.    function GameSwing(totalTime, timeOffset, length, maxAngle)
  26.    {
  27.       super();
  28.       if(totalTime)
  29.       {
  30.          this.totalTime = totalTime;
  31.       }
  32.       if(timeOffset)
  33.       {
  34.          this.timeOffset = timeOffset;
  35.       }
  36.       if(length)
  37.       {
  38.          this.length = length;
  39.       }
  40.       if(maxAngle)
  41.       {
  42.          this.maxAngle = maxAngle;
  43.       }
  44.       this.localLeft = - this.length;
  45.       this.localBottom = this.localRight = this.length;
  46.       this.maxRad = maxAngle / 180 * 3.141592653589793;
  47.    }
  48.    function onAddToWorld()
  49.    {
  50.       this.zone = new SSZone();
  51.    }
  52.    function onAddToScene()
  53.    {
  54.       this.getUpdates();
  55.       this.update(0.0001);
  56.    }
  57.    function onRemoveFromScene()
  58.    {
  59.       this.cancelUpdates();
  60.    }
  61.    function update()
  62.    {
  63.       var _loc3_ = (this.world.time + this.timeOffset) % this.totalTime;
  64.       var _loc4_ = 3.141592653589793 * _loc3_ / this.totalTime * 2;
  65.       var _loc2_ = Math.sin(_loc4_) * 3.141592653589793 * (this.maxAngle / 180);
  66.       this.ltr = _loc2_ > this.ang;
  67.       this.ang = _loc2_;
  68.       this.oax = this.ax;
  69.       this.oay = this.ay;
  70.       this.ax = (this.vx = Math.sin(_loc2_)) * this.length;
  71.       this.ay = (this.vy = Math.cos(_loc2_)) * this.length;
  72.       this.queueForDisplay();
  73.    }
  74.    function onCollision(obj)
  75.    {
  76.    }
  77.    function onDisplay(vp, elapsed)
  78.    {
  79.       this.target.clear();
  80.       this.target.lineStyle(4,13333275);
  81.       this.target.moveTo(0,0);
  82.       if(this.holding)
  83.       {
  84.          var _loc4_ = this.holding.swingDist * 0.5;
  85.          this.target.curveTo(this.vx * _loc4_,this.vy * _loc4_,this.holding.x - this.x,this.holding.y - this.y);
  86.          var _loc3_ = this.oax - this.ax;
  87.          var _loc2_ = this.oay - this.ay;
  88.          var _loc6_ = Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
  89.          this.target.lineTo(this.ax + _loc3_ / elapsed * 0.1,this.ay + _loc2_ / elapsed * 0.1);
  90.       }
  91.       else
  92.       {
  93.          this.target.curveTo(this.ax * 0.4,this.ay * 0.6,this.ax,this.ay);
  94.       }
  95.    }
  96.    function editor_onDisplay(target, external)
  97.    {
  98.       var _loc2_ = (90 - this.maxAngle) / 180 * 3.141592653589793;
  99.       var _loc7_ = Math.cos(_loc2_);
  100.       var _loc6_ = Math.sin(_loc2_);
  101.       target.clear();
  102.       target.lineStyle(0,16742348);
  103.       target.beginFill(16742348,30);
  104.       target.lineTo(_loc7_ * this.length,_loc6_ * this.length);
  105.       var _loc4_ = (1.5707963267948966 - _loc2_) * 0.2;
  106.       var _loc5_ = 10;
  107.       while((_loc5_ = _loc5_ - 1) > -1)
  108.       {
  109.          _loc2_ += _loc4_;
  110.          target.lineTo(Math.cos(_loc2_) * this.length,Math.sin(_loc2_) * this.length);
  111.       }
  112.       target.lineTo(0,0);
  113.       target.endFill();
  114.    }
  115. }
  116.